package com.ews.onlineexchange.controller.assess;

import java.util.List;

import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import com.ews.onlineexchange.model.assess.Dict;
import com.ews.onlineexchange.service.EntityQuery;

@Model
public class DictForSupplierList extends EntityQuery<Dict> {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 1L;

	@Inject
	AssessRecordForSupplierList	assessRecordForSupplierList;

	@Override
	protected List<Predicate> getRestrictions( CriteriaBuilder cb, Root<Dict> entity ) {
		
		List<Predicate> restrictions = super.getRestrictions( cb, entity );
		
		restrictions.add( cb.isTrue( entity.join( "assessClass" ).get("allowSupplierApply") ) );
		restrictions.add( cb.equal( entity.get( "periodType" ), assessRecordForSupplierList.getPeriodType() ) );
		
		return restrictions;
		
	}

	public DictForSupplierList() {
		setMaxResults( null );
		setOrder( "sort ASC, createDate ASC" );
	}

}
